package com.mytest.example.gobrs.task.chain5;

import cn.hutool.core.util.ObjectUtil;
import com.gobrs.async.TaskSupport;
import com.gobrs.async.anno.Task;
import com.gobrs.async.task.AsyncTask;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;


@Slf4j
@Task(desc = "Chain5TaskB")
@Component
public class Chain5TaskB extends AsyncTask<Chain5Param1, String> {
    @Override
    public void prepare(Chain5Param1 o) {

    }

    @SneakyThrows
    @Override
    public String task(Chain5Param1 o, TaskSupport taskSupport) {
        log.info("Chain5TaskB timeout={}", o.getTimeout());
        try {
            if (ObjectUtil.isNotNull(o.getTimeout())) {
                //TimeUnit.SECONDS.sleep(o.getTimeout());
                while (true) {
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "Chain5TaskB";
    }

    @Override
    public boolean nessary(Chain5Param1 o, TaskSupport taskSupport) {
        return true;
    }

    @Override
    public void onSuccess(TaskSupport taskSupport) {
        log.info("Chain5TaskB 执行完成");

    }

    @Override
    public void onFail(TaskSupport taskSupport) {
        //在任务异常时发送告警信息
        log.error("Chain5TaskB 执行失败,ex={}", taskSupport.getResultMap().get(this.getClass()).getEx().getMessage());

    }
}
